<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/view/template.xhtml">
        <ui:define name ="head">
            <script type="text/javascript">
                          function handleSavePost(xhr,status,args) {
                                 if(args.success) {
                                         departmentPostDlg.hide();
                                 }

                         }
                           function handleCreatePost(xhr,status,args) {
                                 if(args.success) {
                                         departmentPostDlg.show();
                                 }

                         }
            </script>
        </ui:define>
        <ui:define  name="content">
            <f:view>
                <h:form id="form1">
                    <p:dataTable value="#{departmentManager.departmentPosts}" var="item" id="departmentPosts" selection="#{departmentManager.selectedDepartmentPost}" selectionMode="single" rowIndexVar="rowIndex" onselectComplete="departmentPostDlg.show()" update="form2:display">
                        <f:facet name="header">
                            <h:panelGrid columns="2" columnClasses="columnLeft,columnRight">
                                <h:selectOneMenu value="#{departmentManager.department}" id="departmentSelectItems">
                                    <f:selectItem itemLabel="部门">
                                    </f:selectItem>
                                    <f:selectItems value="#{departmentManager.departmentItems}" ></f:selectItems>
                                    <p:ajax  update="form1:departmentPosts" listener="#{departmentManager.searchByDepartment}" />
                                </h:selectOneMenu>
                                <h:panelGroup>
                                    <p:commandButton value="新增部门" actionListener="#{departmentManager.createDepartment}" update="form2:display" oncomplete="departmentPostDlg.show();">
                                    </p:commandButton>
                                    <p:commandButton value="新增职位" actionListener="#{departmentManager.createPost}" update="form:growl,form2:display" oncomplete="handleCreatePost(xhr,status,args);">
                                    </p:commandButton>
                                </h:panelGroup>
                            </h:panelGrid>
                        </f:facet>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="职位"/>
                            </f:facet>
                            <h:outputText value="#{item.post}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="启用"/>
                            </f:facet>
                            <h:selectBooleanCheckbox value="#{item.active}" disabled="true"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="提成计算器"/>
                            </f:facet>
                            <h:outputText value="#{item.payrollCalculator}"/>
                        </p:column>

                    </p:dataTable>
                </h:form>
                <p:dialog widgetVar="departmentPostDlg" width="300" header="编辑部门或职位" modal="true">
                    <h:form id="form2">
                        <h:panelGrid columns="2" id="display">
                            <h:outputLabel value="部门:" for="name" />
                            <h:inputText id="name" value="#{departmentManager.selectedDepartmentPost.name}" title="Name" required="true" requiredMessage="请填写部门"/>
                            <h:outputLabel value="职位:" for="post" />
                            <h:inputText id="post" value="#{departmentManager.selectedDepartmentPost.post}" title="Name" required="true" requiredMessage="请填写部门"/>
                            <h:outputLabel value="启用:" for="active" />
                            <h:selectBooleanCheckbox id="active" value="#{departmentManager.selectedDepartmentPost.active}"/>

                            <h:outputLabel value="薪资计算器:" for="calculator"/>
                            <h:selectOneMenu id="calculator" value="#{departmentManager.selectedDepartmentPost.payrollCalculator}">
                                <f:selectItems value="#{applicationBean.payrollCalculatorSelectItems}"/>
                            </h:selectOneMenu>
                            <f:facet name="footer">
                                <h:panelGroup>
                                    <p:commandButton value="保存" actionListener="#{departmentManager.save}"   update="form1:departmentPosts,form:growl,form1:departmentSelectItems" oncomplete="handleSavePost(xhr,status,args)"></p:commandButton>
                                    <p:commandButton value="取消" onclick="departmentPostDlg.hide()"></p:commandButton>
                                </h:panelGroup>
                            </f:facet>
                        </h:panelGrid>
                    </h:form>
                </p:dialog>
            </f:view>
        </ui:define>
    </ui:composition>
</html>
